package avicit.cbb.businessclass.system.dataauth.rest;


import avicit.cbb.businessclass.system.dataauth.domain.CbbAuthResource;
import avicit.cbb.businessclass.system.dataauth.service.BaseExtendAuthService;
import avicit.cbb.businessclass.system.dataauth.service.api.BaseExtendAuthServiceApi;
import avicit.cbb.techclass.billdefine.action.rest.BillDefineManagerRest;
import avicit.platform6.core.context.ThreadContextHelper;
import avicit.platform6.core.rest.msg.ResponseMsg;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@Api(tags = "BaseExtendAuthService", description = "BaseExtendAuth_Service")
@RequestMapping("/api/avicit/cbb/businessclass/system/dataauth/rest/BaseExtendAuthServiceRest")
public class BaseExtendAuthServiceRest {


    private static final Logger LOGGER = LoggerFactory.getLogger(BaseExtendAuthServiceRest.class);


    @Resource(name = "ArchiveServiceUserSetBaseAuthServiceImpl")
    private BaseExtendAuthService archiveServiceUserSetBaseAuthService; // 档案用户数据权限设置服务

    @Resource(name = "BaseAuthService")
    private BaseExtendAuthService baseExtendAuthService;

    /**
     * 获取权限服务的操作类型
     * @param map
     * @return
     */
    @PostMapping("/getOperateInfo")
    @ApiOperation(value = "获取权限服务的操作类型")
    public ResponseMsg<Map<String, String>> getDynamicDetailHtml(@ApiParam(value = "获取权限服务的操作类型", name = "filebasicmanagerservice") @RequestBody Map<String, Object> map) {
        ResponseMsg<Map<String, String>> responseMsg = new ResponseMsg<>();
        try {
            Map<String, String> operateInfo = archiveServiceUserSetBaseAuthService.getOperateInfo();
            responseMsg.setResponseBody(operateInfo);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }

    /**
     * 加载资源配置信息
     * @param map
     * @return
     */
    @PostMapping("/getCbbAuthResource")
    @ApiOperation(value = "加载资源配置信息")
    public ResponseMsg<CbbAuthResource> getCbbAuthResource(@ApiParam(value = "加载资源配置信息", name = "filebasicmanagerservice") @RequestBody Map<String, Object> map) {
        ResponseMsg<CbbAuthResource> responseMsg = new ResponseMsg<>();
        try {

            String orgId = (String) map.get("orgId");
            String sysId = (String) map.get("sysId");
            String targetType = (String) map.get("targetType");
            String targetId = (String) map.get("targetId");
            String authServiceId = (String) map.get("authServiceId");
            String s = (String) map.get("s");
            String lookupCode = (String) map.get("lookupCode");
            CbbAuthResource cbbAuthResource = baseExtendAuthService.getCbbAuthResource(orgId, sysId, targetType, targetId, authServiceId, s, lookupCode);
            responseMsg.setResponseBody(cbbAuthResource);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 删除资源配置信息
     * @param map
     * @return
     */
    @PostMapping("/deleteCbbAuthResource")
    @ApiOperation(value = "删除资源配置信息")
    public ResponseMsg<CbbAuthResource> deleteCbbAuthResource(@ApiParam(value = "删除资源配置信息", name = "filebasicmanagerservice") @RequestBody Map<String, Object> map) {
        ResponseMsg<CbbAuthResource> responseMsg = new ResponseMsg<>();
        try {
            String orgId = (String) map.get("orgId");
            String sysId = (String) map.get("sysId");
            String targetType = (String) map.get("targetType");
            String targetId = (String) map.get("targetId");
            String authServiceId = (String) map.get("authServiceId");
            String s = (String) map.get("s");
            String authType = (String) map.get("authType");
            baseExtendAuthService.deleteCbbAuthResource(orgId, sysId, targetType, targetId, authServiceId, s, authType);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }
}
